package cn.intotw.pp.encode;

import cn.intotw.pp.entity.PPProtocolFrame;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author Chenxiang
 * @Description: 协议帧编码器
 * @create 2018/8/21 14:39
 */
public class PPProtocolEncoder extends MessageToByteEncoder<PPProtocolFrame> {
    protected void encode(ChannelHandlerContext channelHandlerContext, PPProtocolFrame ppProtocolFrame, ByteBuf byteBuf) throws Exception {
        byteBuf.writeInt(ppProtocolFrame.getHeadData());
        byteBuf.writeInt(ppProtocolFrame.getContentLength());
        byteBuf.writeBytes(ppProtocolFrame.getContent());
    }
}